/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-01-26
 * Time: 22:59
 */
public class test3 {
    /**
     * LeetCode 704 二分查找
     */

    public int search(int[] nums, int target) {
        int right = nums.length-1;
        int left = 0;
        while(left<=right){
            int mid = (right-left)/2+left;
            if(nums[mid]<target){
                left = mid+1;
            }else if(nums[mid]>target){
                right = mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
